﻿using Autofac;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Wuther.Entities.Models;
using Module = Autofac.Module;

namespace Wuther.Bussiness.Service.Autofac
{
    public class AutofacModule: Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            // The generic ILogger<TCategoryName> service was added to the ServiceCollection by ASP.NET Core.
            // It was then registered with Autofac using the Populate method. All of this starts
            // with the services.AddAutofac() that happens in Program and registers Autofac
            // as the service provider.
            var baseInterface = typeof(Wuther.Bussiness.Interface.IRepository<>);
            //获取所有需要依赖注入的程序集
            //DDD.Domain是服务所在程序集命名空间  
            Assembly assembly = Assembly.Load("Wuther.Bussiness.Service");
            builder.RegisterAssemblyTypes(assembly)
               .Where(
                b => b.GetInterfaces().Any(c => b.Name.Contains("Repository")
                ))
               .AsImplementedInterfaces()
               .InstancePerDependency();
        }
    }
}
